package com.ning.cloud.framework.security.interceptor;

import com.ning.cloud.framework.security.config.SecurityConfig;
import com.ning.cloud.framework.security.feign.FeignUserInterceptor;
import feign.RequestInterceptor;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Description 拦截器配置
 *
 **/
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {

    @Autowired
    private UserAuthInterceptor userAuthInterceptor;

    @Resource
    SecurityConfig securityConfig;

    @PostConstruct
    public void init(){

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //获取登录用户信息拦截器，所有的接口都经过拦截器，不过滤跳过校验的接口，因为可能传入登录信息
        InterceptorRegistration fequentInterceptor = registry.addInterceptor(this.userAuthInterceptor);
        fequentInterceptor.addPathPatterns("/**");
    }

    /**
     * feign拦截器，传递用户信息
     * @return
     */
    @Bean
    public RequestInterceptor feignUserInterceptor() {
        return new FeignUserInterceptor();
    }


}
